package main

import (
	"fmt"
	"math"
)

type correct interface {
	Correct() string
}

type areaError struct {
	radius float64
	msg    string
}

func (r *areaError) Error() string {
	return fmt.Sprintf("圆的半径是:%.2f,%s", r.radius, r.msg)
}

func (r *areaError) Correct() string {
	return fmt.Sprintf("area圆的半径是：%.2f,%s", r.radius, r.msg)
}

func circleArea(radius float64) (float64, correct, error) {
	if radius <= 0 {
		return 0, nil, &areaError{
			radius: radius,
			msg:    "长度是非法的",
		}
	} else {
		return math.Pi * radius * radius, &areaError{
			radius: radius,
			msg:    "长度是合法的",
		}, nil
	}

}

func main() {
	area, corr, err := circleArea(-12)
	if err != nil {
		fmt.Printf("%v", err)
	} else if corr != nil {
		fmt.Printf("%v,圆的面积是：%.2f", corr, area)
	}
	fmt.Println()
	area1, corr1, err1 := circleArea(12)
	if err1 != nil {
		fmt.Printf("%v", err1)
	} else if corr1 != nil {
		fmt.Printf("%v,圆的面积是：%.2f", corr1, area1)
	}

}
